Component({
  properties: {
    show: {
      type: Boolean,
      value: false,
      observer: function(newVal, oldVal) {
        console.log('address-selector: show 属性变化', '从', oldVal, '到', newVal);
      }
    },
    addressList: {
      type: Array,
      value: [],
      observer: function(newVal) {
        console.log('address-selector: addressList 更新，地址数量:', newVal ? newVal.length : 0);
      }
    },
    currentSchoolCode: {
      type: String,
      value: ''
    },
    selectedAddressId: {
      type: String,
      value: ''
    }
  },

  data: {
    // 组件内部数据
  },

  methods: {
    // 选择地址
    onSelectAddress(e) {
      const index = e.currentTarget.dataset.index;
      const address = this.data.addressList[index];
      
      // 检查地址是否匹配当前学校
      if (address.addressCode !== this.data.currentSchoolCode) {
        wx.showToast({
          title: '该地址对应学校与首页选择的学校不匹配，请返回首页重新选择学校或新增地址',
          icon: 'none',
          duration: 2000
        });
        return;
      }
      
      // 触发选择地址事件
      this.triggerEvent('addressSelect', { address });
    },

    // 新增地址
    onAddAddress() {
      this.triggerEvent('addAddress');
    },

    // 关闭弹窗
    onClose() {
      this.triggerEvent('close');
    },

    // 阻止事件冒泡
    onStopPropagation() {
      // 阻止事件冒泡，防止点击内容区域时关闭弹窗
    }
  }
});
